package network;

import java.util.HashMap;
import java.util.HashSet;

public class Port {
    public static int cnt = 0;
    public static HashMap<Integer, Port> uidToPort = new HashMap<>();
    public int uid;

    private String name;
    private Device device;
    private HashSet<Port> peers;

    /**
     * A Port takes a unique name and belongs to a unique Device.
     *
     * @param name the port name
     * @param device the device that owns this port
     */
    public Port(String name, Device device) {
        this.name = name;
        this.device = device;
        this.peers = new HashSet<>();

        this.uid = cnt;
        cnt ++;
        uidToPort.put(this.uid, this);
    }

    public String getName() {
        return name;
    }

    public Device getDevice() {
        return device;
    }

    public HashSet<Port> getPeers() {
        return this.peers;
    }

    public void addPeer(Port peer) {
        this.peers.add(peer);
    }
}
